package com.cskaoyan.controller.admin.promotion;

import com.cskaoyan.bean.BaseParamBo;
import com.cskaoyan.bean.BaseRespData;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.admin.promotion.bo.TopicBo;
import com.cskaoyan.bean.admin.promotion.vo.TopicVo;
import com.cskaoyan.service.admin.PromotionService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Name : TopicController.java
 * @Time : 2021/8/12 19:36
 * @Author : creamycandy
 * @Software : IntelliJ IDEA
 */

@RestController
@RequestMapping("admin/topic")
public class TopicController {

    @Autowired
    PromotionService promotionService;

    @RequiresPermissions(value = {"*", "admin:topic:list"}, logical = Logical.OR)
    @RequestMapping("list")
    public BaseRespVo getTopicList(String title, String subtitle, BaseParamBo param){
        BaseRespData respData = promotionService.getTopicList(title, subtitle, param);
        return BaseRespVo.ok(respData);
    }

    @RequiresPermissions(value = {"*", "admin:topic:create"}, logical = Logical.OR)
    @RequestMapping("create")
    public BaseRespVo createTopic(@RequestBody TopicBo topicBo){
        TopicVo topic = promotionService.createTopic(topicBo);
        return BaseRespVo.ok(topic);
    }

    @RequiresPermissions(value = {"*", "admin:topic:update"}, logical = Logical.OR)
    @RequestMapping("update")
    public BaseRespVo updateTopic(@RequestBody TopicBo topicBo){
        TopicVo topicVo = promotionService.updateTopic(topicBo);
        if(topicVo==null){
            return BaseRespVo.fail("没有察觉任何修改~");
        }
        return BaseRespVo.ok(topicVo);
    }

    @RequiresPermissions(value = {"*", "admin:topic:delete"}, logical = Logical.OR)
    @RequestMapping("delete")
    public BaseRespVo deleteTopic(@RequestBody TopicBo topicBo){
        promotionService.deleteTopic(topicBo);
        return BaseRespVo.ok();
    }
}
